/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.httpsdk.http.face;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;

import logic.constants.AppConfig;
import logic.constants.Const;
import logic.util.Util;

import org.json.JSONObject;

import android.content.Context;

import com.shwread.httpsdk.constant.ResultCode;
import com.shwread.httpsdk.http.base.AbstractHttpPostDracom;
import com.shwread.httpsdk.http.callback.ActionListener;


/**
 * 添加评论
 * @author 刘宾  
 * @date 2015年2月2日 下午6:16:50
 */
public class AddCommentAction
        extends
        AbstractHttpPostDracom
{
	private String targetType;//评论的内容类型
	private String targetValue;//评论的内容值
	private String content;//评论内容
	
	private Long targetUserId;//被回复的目标对象的用户id
	private String targetUserAccount;//被回复的目标对象的用户账号
	private Long commentId;//被回复的评论记录记录id
	
	/**
	 * 添加评论
	 * @param context
	 * @param targetType 评论的内容类型
	 * 			1=书籍 2=专区内容(资讯、视音频等类型) 3=图集图片 4=图集
	 * @param targetValue 评论的内容值
	 * 		   	如果targetType为1，则为书籍id;如果targetType为2，则为对应的内容详细id;如果targetType为3；则为图片id;如果targetType为4，则为图集栏目id.
	 * @param content 评论内容
	 * @param targetUserId <选填>被回复的目标对象的用户id
	 * @param targetUserAccount <选填>被回复的目标对象的用户账号
	 * @param commentId <选填>被回复的评论记录记录id
	 * @param actionListener
	 */
	public AddCommentAction(Context context,String targetType,String targetValue,String content,Long targetUserId,String targetUserAccount,Long commentId, ActionListener actionListener) {
		super(context, "addComment.do", actionListener);
		this.targetType = targetType;
		this.targetValue = targetValue;
		this.content = content;
		if(null != targetUserId) this.targetUserId = targetUserId;
		if(Util.isNotEmpty(targetUserAccount)) this.targetUserAccount = targetUserAccount;
		if(null != commentId) this.commentId = commentId;
	}
	
	@Override
	public void getParameter(HashMap<String, String> parameter_map) {
		parameter_map.put("account", Const.phone_number);
		parameter_map.put("timeStamp", String.valueOf(timeStamp));
		
		parameter_map.put("enterpriseId", AppConfig.getEnterpriseId());
		parameter_map.put("targetType", targetType);
		parameter_map.put("targetValue", targetValue);
//		parameter_map.put("content", content);
		try
        {
            parameter_map.put("content", URLEncoder.encode(content, "utf-8"));
        }
        catch (UnsupportedEncodingException e)
        {
        	parameter_map.put("content", "");
            e.printStackTrace();
        }
		if(null != targetUserId) parameter_map.put("targetUserId", String.valueOf(targetUserId));
		if(Util.isNotEmpty(targetUserAccount)) parameter_map.put("targetUserAccount", targetUserAccount);
		if(null != commentId) parameter_map.put("commentId", String.valueOf(commentId));
		
		parameter_map.put("cid", cid(Const.phone_number + Const.ACCOUNTTYPE + Const.CLIENTTYPE + timeStamp + AppConfig.getEnterpriseId() + targetType+targetValue));
	}
	
	@Override
	public void doResponseXml(String xml) {
		println("addComment --> "+xml);
		int result = -1;
		try
		{
			JSONObject jsonObject = new JSONObject(xml);
			result = jsonObject.getInt("resultCode");
			if (result == 1000)
			{
				listener.OK(true);
			}
			else
			{
				listener.ERROR(result, ResultCode.getResultText(result));
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	@Override
	protected void doRequestHeader(HashMap<String, String> header_map) {
		
	}
	
	@Override
	public void dispose() {
		
	}
	
}
